import { Auth } from '@/decorator/auth.decorator';
import { idIsExistPipe } from '@/pipe/idIsExistPipe';
import { Body, Controller, Get, Param, Post, Query, Req } from '@nestjs/common';
import { Request } from 'express';
import { CreateSendMailDto } from './dto/create-send.mail.dto';
import { queyrDataDto } from './dto/queyrDataDto';
import { SendMailService } from './send.mail.service';
@Controller('sendMail')
export class SendMailController {
  constructor(private readonly sendMailService: SendMailService) {}
  @Auth()
  @Post()
  create(@Body() createSendMailDto: CreateSendMailDto, @Req() req: Request) {
    return this.sendMailService.create(createSendMailDto, req);
  }
  /**
   * 随机读取一封信
   *
   */
  @Get()
  randomReading() {
    return this.sendMailService.randomReading();
  }
  /**
   * 分页查询信件
   */
  @Get('paging')
  findAll(@Query() query: queyrDataDto) {
    query = { page: 1, size: 10, ...query };
    return this.sendMailService.findAll(query);
  }

  /**
   * 查询本人自己的信
   */
  @Auth()
  @Get('findSelfMail')
  findSelfMail(@Req() req: Request) {
    return this.sendMailService.findSelfMail(req);
  }
  /**
   * 删除信件
   *
   */
  @Auth()
  @Get('remove/:id')
  remove(@Param('id', new idIsExistPipe('postOffice')) id: string) {
    return this.sendMailService.remove(id);
  }
  /**
   * 根据id 查询信件详情
   */
  @Auth()
  @Get('getMailInfo/:id')
  getMailInfo(@Param('id', new idIsExistPipe('postOffice')) id: string) {
    return this.sendMailService.getMailInfo(id);
  }
  /**
   * 测试发信
   * @param 参数名 {参数类型} 描述信息
   * @returns 返回数据的的描述
   */
  @Get('testSendMail')
  testSendMail() {
    return this.sendMailService.testSendMail();
  }
}
